package com.sss.springcloud.controller;


import com.sss.springcloud.common.Result;
import com.sss.springcloud.entities.Payment;
import com.sss.springcloud.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sss
 * @since 2020-03-05
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Value("${server.port}")
    private String server_port;

    @Autowired
    private IPaymentService paymentService;

    @PostMapping("/create")
    public Result create(@RequestBody Payment payment){
            paymentService.save(payment);
        Long id = payment.getId();
        return Result.succes(id);
    }

    @GetMapping("/get/{id}")
    public Result getPayment(@PathVariable Long id){
        return Result.succes("server-port:"+server_port,paymentService.getById(id));
    }

    @GetMapping("/get/ribbon")
    public Result getRibbon(){
        return Result.succes("server-port:"+server_port);
    }

    @GetMapping("/feign/timeout")
    public Result getTimeout(){
        try {
            TimeUnit.SECONDS.sleep(8);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return Result.succes("Feign****Timeout");
    }
}

